package com.treasure.mall.biz.service.core.impl;

import com.treasure.mall.biz.entity.order.DeliverBillPO;
import com.treasure.mall.biz.entity.order.RebateBillPO;
import com.treasure.mall.biz.entity.order.SettlementBillPO;
import com.treasure.mall.biz.service.core.ScheduledService;
import com.treasure.mall.biz.service.core.order.DeliverService;
import com.treasure.mall.biz.service.core.order.RebateBillService;
import com.treasure.mall.biz.service.core.order.SettlementBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/7/31
 */
@Service
@Slf4j
public class ScheduledServiceImpl implements ScheduledService {
    @Autowired
    private RebateBillService rebateBillService;
    @Autowired
    private SettlementBillService settlementBillService;
    @Autowired
    private DeliverService deliverService;

    @Override
    public void receive() {
        List<DeliverBillPO> pos = deliverService.findToReceive();

        for (DeliverBillPO po : pos) {
            try {
                deliverService.receive(po);
            } catch (Exception e) {
                log.info("发货单" + po.getId() + "自动签收失败===" + e.getMessage());
            }
        }
    }

    @Override
    public void convertRebate() {
        //得到到了转正时间并且待转正的佣金单据
        List<RebateBillPO> rebateBillPOS = rebateBillService.findToConvert();

        for (RebateBillPO rebateBillPO : rebateBillPOS) {
            try {
                rebateBillService.convert(rebateBillPO);
            } catch (Exception e) {
                log.info("佣金单" + rebateBillPO.getId() + "自动结算失败===" + e.getMessage());
            }
        }
    }

    @Override
    public void convertSettlement() {
        List<SettlementBillPO> pos = settlementBillService.findToConvert();
        for (SettlementBillPO po : pos) {
            try {
                settlementBillService.convert(po);
            } catch (Exception e) {
                log.info("结算单" + po.getId() + "自动结算失败===" + e.getMessage());
            }
        }
    }
}
